﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using SongSharp.Domain.Objects;

namespace SongSharp.Domain.Playlisting.M3U
{
    public abstract class M3UReader
    {
        public static Playlist CreateFromFile(string path)
        {
            return CreateFromFile(path, null, false);
        }

        public static Playlist CreateFromFile(string path, string name, bool readOnly)
        {
            Playlist playlist = new Playlist();
            playlist.Url = path;
            playlist.ReadOnly = readOnly;
            playlist.Name = name;

            foreach (string line in File.ReadAllLines(path))
            {
                Match match = Regex.Match(line, "^[^#]");
                if (match.Success)
                    playlist.Tracks.Add(new Track(line));
            }
            return playlist;
        }
    }
}
